<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='姓名'>
              <a-input placeholder='请输入姓名' v-model='queryParam.name'></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="8" :sm="12">
            <a-form-item label="申请月份">
              <j-date
                placeholder="请选择开始时间"
                class="query-group-cust"
                v-model="queryParam.salaryTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                placeholder="请选择结束时间"
                class="query-group-cust"
                v-model="queryParam.salaryTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>
      <a-button type='primary' icon='download' @click="handleExportXls('工资申请-浮动值')">导出</a-button>
      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'
                @change='handleImportExcel'>
        <a-button type='primary' icon='import'>导入</a-button>
      </a-upload>
      <a-button @click='handleCount' type='primary' icon='plus'>汇总</a-button>
      <!-- 高级查询区域 -->
      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-button style='margin-left: 8px'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        class='j-table-force-nowrap'
        @change='handleTableChange'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='downloadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'>编辑</a>

          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a @click='handleDetail(record)'>详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <hf-wage-salary-volatility-modal ref='modalForm' @ok='modalFormOk'></hf-wage-salary-volatility-modal>
    <j-modal
      :title='countTitle'
      :width='400'
      :visible='countVisible'
      @ok='handleCountOk'
      @cancel='handleCountCancel'
      cancelText='关闭'>
      <div >
        <span>选择月份：</span>
        <a-month-picker style='width: calc(100% - 70px)' placeholder='请选择月份' @change='monthChange' />
      </div>
    </j-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import HfWageSalaryVolatilityModal from './modules/HfWageSalaryVolatilityModal'
import { splitByNum } from '@/utils/util'
import moment from 'moment'
import { getAction, postAction } from '@api/manage'

export default {
  name: 'HfWageSalaryVolatilityList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    HfWageSalaryVolatilityModal
  },
  data() {
    return {
      description: '工资申请-浮动值管理页面',
      // 表头
      countTitle: '汇总',
      countVisible: false,
      selectedMonth: 0,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '日期',
          align: 'center',
          dataIndex: 'salaryTime'
        },
        {
          title: '姓名',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '绩效考核得分',
          align: 'center',
          dataIndex: 'performanceAppraisalScore_dictText',
        },
        {
          title: '应出勤天数',
          align: 'center',
          dataIndex: 'attendanceDay',
        },
        {
          title: '实际出勤天数',
          align: 'center',
          dataIndex: 'actualAttendanceDay',
        },
        {
          title: '报工天数',
          align: 'center',
          dataIndex: 'workDay',
        },
        {
          title: '全勤奖',
          align: 'center',
          dataIndex: 'attendanceBonus',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: 'BM补助',
          align: 'center',
          dataIndex: 'bmAllowance',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '管理津贴',
          align: 'center',
          dataIndex: 'managementAllowance',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '奖励金',
          align: 'center',
          dataIndex: 'incentivePayment',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '电脑补助',
          align: 'center',
          dataIndex: 'computerAllowance',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '出差补助',
          align: 'center',
          dataIndex: 'travelAllowance',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        // {
        //   title: '请假',
        //   align: 'center',
        //   dataIndex: 'askForLeave',
        //   customRender: (t, item, index) => {
        //     return splitByNum(+t)
        //   }
        // },
        {
          title: '扣款',
          align: 'center',
          dataIndex: 'deductMoney',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '社保年检补缴',
          align: 'center',
          dataIndex: 'socialSecurityCheck',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '个税',
          align: 'center',
          dataIndex: 'payTaxes',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '其他扣款',
          align: 'center',
          dataIndex: 'otherDeductMoney',
          customRender: (t, item, index) => {
            return splitByNum(+t)
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/wage/hfWageSalaryVolatility/list',
        delete: '/wage/hfWageSalaryVolatility/delete',
        deleteBatch: '/wage/hfWageSalaryVolatility/deleteBatch',
        count: '/wage/hfWageSalaryVolatility/count',
        exportXlsUrl: '/wage/hfWageSalaryVolatility/exportXls',
        importExcelUrl: 'wage/hfWageSalaryVolatility/importExcel'

      },
      dictOptions: {},
      queryModel:true

    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    moment,
    handleCountOk() {
      getAction(this.url.count, { selectedMonth: this.selectedMonth }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.countVisible = false
        } else {
          this.$message.error(res.message)
        }
      })
    },
    monthChange(date) {
      this.selectedMonth = moment(date).format('YYYY-MM')
    },
    handleCountCancel() {
      this.countVisible = false
    },
    handleCount() {
      this.countVisible = true
    },
    initDictConfig() {
    },
    onDateChange: function (value, dateString) {
      console.log(dateString[0],dateString[1]);
      this.queryParam.salaryTime_begin=dateString[0];
      this.queryParam.salaryTime_end=dateString[1];

    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>